<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="登录名">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
    </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
        this.$axios.post('/api/login',this.form)
        .then(({data})=>{
            console.log(data)
            if(data.code==200){
                this.$message(data.msg);
            } else {
                this.$message(data.msg);
            }
        })
        .catch( (error) => {
            // 处理错误情况
            console.log(error);
        });

    },
  },
};
</script>